package com.ruoyi.legal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.ResponseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.Pages;
import com.ruoyi.common.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.legal.domain.PackAjtz;
import com.ruoyi.legal.service.IPackAjtzService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * 案件台账备份Controller
 * 
 * @author xwj
 * @date 2025-05-10
 */
@RestController
@RequestMapping("/legal/packAjtz")
@Api(tags = "案件台账备份")
public class PackAjtzController extends BaseController {
    @Autowired
    private IPackAjtzService packAjtzService;

    /**
     * 查询案件台账备份列表
     */
    @PostMapping("/list")
    @ApiOperation("分页查询")
    public TableDataInfo list(@RequestBody PackAjtz packAjtz) {
        startPage();
        List<PackAjtz> list = packAjtzService.selectPackAjtzList(packAjtz);
        return getDataTable(list);
    }

    @PostMapping("/listAll")
    @ApiOperation("不分页查询")
    public AjaxResult listAll(@RequestBody PackAjtz packAjtz) {
        startOrderBy();
        List<PackAjtz> list = packAjtzService.selectPackAjtzList(packAjtz);
        return success(list);
    }

    /**
     * 导出案件台账备份列表
     */
    @Log(title = "案件台账备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出")
    public void export(HttpServletResponse response, PackAjtz packAjtz) {
        List<PackAjtz> list = packAjtzService.selectPackAjtzList(packAjtz);
        ExcelUtil<PackAjtz> util = new ExcelUtil<PackAjtz>(PackAjtz.class);
        util.exportExcel(response, list, "案件台账备份数据");
    }

    /**
     * 获取案件台账备份详细信息
     */
    @GetMapping(value = "/info/{id}")
    @ApiOperation("详情")
    public AjaxResult info(@PathVariable("id") Long id)  {
        return success(packAjtzService.selectPackAjtzById(id));
    }

    /**
     * 新增案件台账备份
     */
    @Log(title = "案件台账备份", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增")
    public AjaxResult save(@RequestBody PackAjtz packAjtz) {
        SysUser user = getLoginUser().getUser();
        if(packAjtz.getId() == null) {
        packAjtz.setCreateId(user.getUserId());
            packAjtz.setCreateTime(DateUtils.getNowDate());
            packAjtz.setCreateBy(user.getNickName());
            packAjtzService.insertPackAjtz(packAjtz);
        } else {
            packAjtz.setUpdateId(user.getUserId());
            packAjtz.setUpdateTime(DateUtils.getNowDate());
            packAjtz.setUpdateBy(user.getNickName());
            packAjtzService.updatePackAjtz(packAjtz);
        }

        return success(packAjtz);
    }

    /**
     * 修改案件台账备份
     */
    @Log(title = "案件台账备份", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody PackAjtz packAjtz) {
        SysUser user = getLoginUser().getUser();
                packAjtz.setUpdateId(user.getUserId());
                packAjtz.setUpdateTime(DateUtils.getNowDate());
                packAjtz.setUpdateBy(user.getNickName());
        return success(packAjtzService.updatePackAjtz(packAjtz));
    }

    /**
     * 删除案件台账备份
     */
    @Log(title = "案件台账备份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除或批量删除")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(packAjtzService.deletePackAjtzByIds(ids));
    }

    @Log(title = "案件台账备份", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    @ApiOperation("条件删除")
    public ResponseModel delete(@RequestBody PackAjtz packAjtz) {
        int num = packAjtzService.delete(packAjtz);
        return ResponseModel.of(num);
    }

    @PostMapping("/queryPage")
    @ApiOperation("分页查询-mp")
    public ResponseModel<Pages<PackAjtz>> queryPage(@RequestBody PackAjtz packAjtz) {
        Pages<PackAjtz> page = packAjtzService.queryPage(packAjtz);
        return ResponseModel.of(page);
    }
}
